<?php
namespace admin\action;

use herosphp\bean\Beans;
use herosphp\exception\UnSupportedOperationException;
use herosphp\http\HttpRequest;
use herosphp\utils\AjaxResult;

/**
 * setting action
 * @package system\action
 * @author yangjian<yangjian102621@gmail.com>
 */
class SettingAction extends CommonAction {

    protected $serviceBean = 'system.setting.service';
    protected $actionTitle = '系统设置';

    //数据列表页面
    public function index( HttpRequest $request ) {
        $service = Beans::get($this->getServiceBean());
        $item = $service->getSettings();
        $this->assign('item', $item);
        $this->setView('system/setting');
        $this->assign('breadcrumb', array('系统管理', '系统设置'));
    }

    //数据添加页面
    public function add(HttpRequest $request) {
        throw new UnSupportedOperationException('暂时不支持的该操作');
    }

    //数据编辑页面
    public function edit(HttpRequest $request) {
        throw new UnSupportedOperationException('暂时不支持的该操作');
    }

    //插入数据操作
    public function insert(HttpRequest $request) {

        throw new UnSupportedOperationException('暂时不支持的该操作');
    }

    //更新数据操作
    public function update(HttpRequest $request) {

        $data = $request->getParameter('data');
        $service = Beans::get($this->getServiceBean());
        if ( $service->update($data, null) ) {
            $request->addParameter('logmessage', "更新了系统设置");
            AjaxResult::ajaxSuccessResult();
        } else {
            AjaxResult::ajaxFailtureResult();
        }

    }
}
